	/********************************************
	 * Hiyees。Com call banner 控制类js
	 * @Function ： 对callbanner的基本通讯、高级功能、组长功能等交互模块进行
	 *            模块的逻辑控制
	 * @author   : 
	 * @create   :
	 * @Companny :
	 ********************************************/ 
	/******************************
	 * 状态表
	返回: -1:未连接到Red5(或者连接到Red5失败),0:签出(或者签入失败),1:签入,
	2:上线,3:服务中与用户通话,4:置忙,5:保持,6:咨询坐席,7:咨询外线,
	8:三方通话,9:监听坐席,10:插话,11 :上线置忙,
	12：坐席拨打用户，用户正在振铃。
	 *************************************************/
	var  callStateHelper = function(){
         //* 状态表  -1:未连接到Red5(或者连接到Red5失败),0:签出(或者签入失败),1:签入,	2:上线,3:服务中与用户通话,4:置忙,5:保持,6:咨询坐席,7:咨询外线,	8:三方通话,9:监听坐席,10:插话,11 :上线置忙,	12：坐席拨打用户，用户正在振铃。
		var callstate=1,callseat=0,busy=0,hold=0,inmeet=0,calltouser=0,moniter_insert=0 ;
		return	{			  
		    //呼叫状态表
			disconnect:-1,
			logout:0,
			login:1,
			online:2,
			talking:3,
			using:30,
			callcusting:31,
			custring:32,
			busy:4,
			hold:5,
			consultagc:6,  //咨询坐席中
			consultuser:7,  //咨询外部用户（专家席）
			conference:8,  //会议
			monitor:9,
			insert:10,   //插话
			busyonline:11, //上线忙
			ring:12 ,    //振铃 呼入、呼出
			whisper:13,  //耳语
			agctalk:14,
			ring3:15,  //咨询振铃
			//以2开头为示忙原因的虚拟主状态，以此在前端实现多个“忙”状态的解释与切换控制
			busylogin:209,  //示忙- 忙碌
			busyonlinelogin:219,  //示忙- 忙碌
			busyonline201:201,  //上线忙 - 小休
			busyrest:202,  //示忙 - 小休
			busy211:211,  //示忙 - 小休
			busyonlinerest:212,  //示忙 - 小休	
			robcall:220,  //拦截
			getText:function(state)
			{
				switch(parseInt(state))
				{
				case -1:    return "未连接"; 
				case 0:	    return "签出";
				case 1:	    return "空闲";
				case 2:	    return "上线";
				case 30:	return "拨号中";
				case 3:	    return "通话";
				case 31:	return "呼叫用户";
				case 32:	return "用户振铃";
				case 4:     return "忙碌";
				case 5:	    return "保持";
				case 6:     return "咨询";
				case 7:	    return "咨询";
				case 8:	    return "会议";
				case 9:	    return "监听";
				case 10:	return "插话";
				case 11:	return "上线忙";
				case 12:	return "振铃"; 
				case 13:	return "耳语";
				case 14:	return "同事";
				case 15:    return "咨询呼出" ;
				case 201:    return "忙碌";
				case 202:    return "小休";
				case 209:    return "签入忙";
				case 219:    return "签入忙";
				case 211:    return "忙碌";	
				case 212:    return "小休";		
				case 220:    return "拦截";
				default:    return "未知"+state;
				}
			},
			getCurCallState:function() { return callstate ;}, 
			setCallState:function(_state) { callstate = _state ;}
		};
	}() ;
	
	 /***************************
     * 呼叫随路数据帮助类 
     *   上线数据的解析
     */
    var callDataHelper = function(){
    	var iscallin=true , caller ="", called ="", uid="", cdrid="",calldata="",isagc=true,telno="",ext="", custvalues=[]; //客户变量
    	var ringTime="",ansTime="",endTime="",workTimeLen=0,talkTimeLen=0  ,  businessdata58 = null ,cmsCreateTime, ansTS = null ;
    	var isTalking =false , sendCdrId="",callpos=-1;
    	var hostOffTime = 0 ;
    	var callEvent=null ;
    	/*api定义*/
    	return {
    		setCallEvent:function(_event)
    		{
    			callEvent = _event ;
    		},
    		getCallEvent:function(){
    			return callEvent ;
    		},
    		 
    		/*************
    		 * 外部调用赋值 isAgc:isagc,  
    		 */
    		isAgc:isagc,  //给当前对象赋值
    		telNo:telno,
    		//外部获取本对象内部变量    		 
    		setBusinessdata58:function(_data58){
    			businessdata58 = _data58 ; //这是map对象    			
    		},
    		setCmsCreateTime:function(_time)
    		{
    			cmsCreateTime = _time ;	
    		},
    		getCmsCreateTime:function()
    		{
    			return cmsCreateTime;	
    		}, 
    		 
    		getHostOffTime:function(){return hostOffTime ;} ,
    		
    		getBusinessdata58:function(){
    			return businessdata58 ; //这是map对象    			
    		},    		 
    		 
    		restData:function () {
    	    	caller ="", called ="", uid="", cdrid="",calldata="",isagc=true,telno="",ext=""; //客户变量
    	    	ringTime="",ansTime="",endTime="",workTimeLen=0,talkTimeLen=0  ,  businessdata58 = null , ansTS = null ;
    		},
    		//是否已经发送了
    		getSendCmsOK:function(){   return  sendCdrId == cdrid? true:false  ;} ,
    		UpdateSendCms:function(){  sendCdrId = cdrid ;}  
    	} ;
    }() ;	
	 	
	/***********************
	 * 与flashgate通信类变量定义
	 * 
	 ************************/	
	var g_LastCallStateTimeSP = new Date() ;
	var g_BeginAnsTimeSP = new Date() ;
	
	var g_IsSipPhone = false ; //
	var g_ImgPath = "./images";
	 //按钮的不可用状态显示方式： disable = 采用 xx_1.png 的不可用含义icon 显示， hidden ：不可用直接隐藏
	var g_DisEnableBtnStyle = "hidden" ;
	var g_Button_Icon_Text = "text" ;  //按钮样式， icon 图标， text 文本
	  
	var g_ServerInfo =     //服务器参数
		{
			curServer:"",red5Url1:"",cmsUrl1:"",sipServerUrl1:"", wsServers1:"", stunServers1:"",
			red5Url2:"",cmsUrl2:"",sipServerUrl2:"", wsServers2:"", stunServers2:""
		};
	var g_CmsUrl=""; 
	var g_AcdInfo = {		
		    		  entId:0,     //企业编码
		    		  entPwd:"",  //企业账户密码
		    		  isLeader:0, //组长席1，否则0
		    		  optId:"",   //坐席工号, 当前坐席的操作员号
		    		  optPwd:"",
		    		  name:"",
		    		  qId:0, 
		    		  extType:1, // 绑定电话类型：0：pstn电话坐席，1：sip，IP坐席
		    		  extNum:0,
		    		  loginType:0,      //签入方式： 0=坐席签入，这里固定用0， 1=外线签入（由班长席执行代签入时，有系统配置确定）
		    		  tokenId:"" ,
		    		  isCheckIn:false 
		    		} ;     
	 var g_StateTimer = null;
	 /***************************************************
	  * 状态持续时长计时，输出包括：主状态，子状态
	  * 当子状态有输出时，主状态一定有输出如：通话，主：通话+号码， 子：持续时长
	  *  如: 小休状态， 通话时长等  
	  **************************************************/
     function setStateTimer(tmpMsg,begdt) {
    	 var prompt = tmpMsg +" "+ calculateTimeSpan(begdt) ;
    	 showMainStatus(prompt) ;
		 g_StateTimer =setTimeout( function(){
					setStateTimer(tmpMsg,begdt);
			 	     },1000) ;
     }
     /*
      * callEvent
      * **/
     function setTalkTimer(tmpMsg,begdt) { 	 
	   	 var prompt = tmpMsg +" "+ calculateTimeSpan(begdt) ;    	    	 
       	 showMainStatus(prompt) ;
    	 g_StateTimer =setTimeout( function(){
    	 setTalkTimer(tmpMsg,begdt);
         },1000) ;
     }
	/***********************************
	 * 呼叫状态变化，显示提示信息，只对substatus配置
	 * @param state
	 */
	function showCStateMsg(_state)
	{		
		clearTimeout(g_StateTimer);
		g_StateTimer = null;   //当状态变更了，系统停止前一状态的计时
		var strState= callStateHelper.getText (_state.callstate) ;		
	    var offts = new Date().getTime() - Number(_state.hostmillis);
	    if( isNaN(offts)) offts = 0 ;	
	    var tdt	 = new Date(_state.statetime.replace(/-/g,"/")) ;
	    var rDt =  new Date(  tdt.getTime()  + offts );

		
		switch(parseInt(_state.callstate))
			{
				case callStateHelper.logout:  //已签出了， 显示可签入   显示基本通讯功能面板，且仅签入“按钮”可用
			    { // 此类状态不计时
					 showMainStatus(strState) ;
				   return ;  //不需要计时，在主状态显示， 子状态清空
				}
				case callStateHelper.disconnect:  //-1, 未连接到服务器或连接失败
			    { // 此类状态不计时
					showMainStatus(strState) ;
				   return  ;  //不需要计时，在主状态显示， 子状态清空
				}
				case callStateHelper.online:  //2 上线 ， 可电话了	 
				case callStateHelper.login:  //已签入， 可电话了	  显示基本通讯功能面板，
				case callStateHelper.busy:  //4 忙， 只能呼出	 
				case callStateHelper.busyonline:  //11 上线 忙	 
				case callStateHelper.busylogin:  //11 上线 忙	 
				case callStateHelper.busyonlinelogin:  //11 上线 忙	 
					
				case callStateHelper.busyonline201:  //11 上线 忙
				case callStateHelper.busyrest:  //11 上线 忙	 
				case callStateHelper.busy211:
				case callStateHelper.using:
					
				case callStateHelper.busyonlinerest:  //11 上线 忙	 
			    {
					//showMainStatus(strState) ;
					setStateTimer(strState,rDt) ; //设置计时器 ，参数为前缀， 持续:0:0:10秒 
				    return ;
				} 	
				case callStateHelper.hold:  //保持
				case callStateHelper.ring:  //呼出振铃，呼入没有事件通知
				case callStateHelper.monitor:
				case callStateHelper.insert:
				case callStateHelper.robcall:
				case callStateHelper.agctalk:  //3 ，电话中	
				case callStateHelper.callcusting:
				case callStateHelper.custring:
				{  	 
					return setStateTimer(strState+":",rDt) ;
				}
				//下面这部分的计时需要从通话建立后计算，中间状态均包含在内
				case callStateHelper.consultagc:
				case callStateHelper.consultuser:
				case callStateHelper.conference: 
				case callStateHelper.talking:  //3 ，电话中	  getAnswerTS
				{ 
					var tdt =  new Date();
					var offts = 0 ;
					if( FlashAgentX.g_callEvent != null) 
					{
						offts = FlashAgentX.g_callEvent.offts ;  
	    	    	 if(FlashAgentX.g_callEvent.callstate3==2 && FlashAgentX.g_callEvent.anstime3 != "")
	    	    		 tdt	 = new Date(FlashAgentX.g_callEvent.anstime3.toString().replace(/-/g,"/")) ;
	    	    	 else
	    	    		 if( FlashAgentX.g_callEvent.anstime != "")
		    	    		 tdt	 = new Date(FlashAgentX.g_callEvent.anstime.toString().replace(/-/g,"/")) ;
					}
		             var rDt =  new Date(  tdt.getTime()  + offts );
					return setTalkTimer(strState+":", rDt) ;
				}
			}
	 	}
	
	
	/*************************************************
	 * 计算时差
	 */
	 
	function calculateTimeSpan(begTime)
	{ 
		var date3=new Date().getTime()-begTime.getTime() ;  //时间差的毫秒数
		if(date3 <0) date3 = 0 ;
		//计算出相差天数
		var days=Math.floor(date3/(24*3600*1000));
		//计算出小时数
		var leave1=date3%(24*3600*1000)   ; //计算天数后剩余的毫秒数
		var hours=Math.floor(leave1/(3600*1000));
		//计算相差分钟数
		var leave2=leave1%(3600*1000)       ; //计算小时数后剩余的毫秒数
		var minutes=Math.floor(leave2/(60*1000));
		//计算相差秒数
		var leave3=leave2%(60*1000);      //计算分钟数后剩余的毫秒数
		var seconds=Math.round(leave3/1000);
	    return 	 hours+":"+minutes+":"+seconds ;
	}
	 	 

	function onGetAcdInfo(errcode,errmsg,data)
	{
		if(errcode != "0"){
			showSubStatus("GetAcdInfo失败:"+errmsg); 
			return ;
		}				
		var isLeader = data.isleader == 1 ? true:false ;
		g_AcdInfo.optPwd = data.workpassword ; 
		g_AcdInfo.qId = data.queueid ;
		g_AcdInfo.name = data.workname ; 
	    g_AcdInfo.extType = 0 ;  
		if( g_AcdInfo.extNum == 0 ) //crm没有临时指定坐席分机，采用系统预定义的分机
		{
		  g_AcdInfo.extNum = data.extentionno ; 
		}
		if(g_AcdInfo.extNum  == 0 || g_AcdInfo.extNum =="0"||g_AcdInfo.extNum =="0000")
		{	       
	       if(confirm("对不起，你的工号:"+g_AcdInfo.optId+" 尚未绑定话机，您可现在绑定好后点击确认继续，也可暂时放弃，下次绑定好后重新登录？"))
	    	   {
	    	     return cmsHelper.getAcdInfo(onGetAcdInfo2) ;        	   
	    	   }else
	    	   {
	    	     return ;	   
	    	   }
		}
		//showSubStatus("getacdinfo成功!"); 		
		//检查如果使用webphone
		if(g_IsSipPhone )
		    cmsHelper.getServerInfo(onGetServerInfo) ;
		else
			cmsHelper.getServiceNode(onGetServiceNode,g_AcdInfo.extNum) ;	
		}
	//临时绑定话机的2此登录
	function onGetAcdInfo2(errcode,errmsg,data)
	{
		if(errcode != "0"){
			showSubStatus("GetAcdInfo失败:"+errmsg); 
			return ;
		}				
		var isLeader = data.isleader == 1 ? true:false ;
		g_AcdInfo.optPwd = data.workpassword ; 
		g_AcdInfo.qId = data.queueid ;
		g_AcdInfo.name = data.workname ; 
	    g_AcdInfo.extType = 0 ;  
		if( g_AcdInfo.extNum == 0 ) //crm没有临时指定坐席分机，采用系统预定义的分机
		{
		  g_AcdInfo.extNum = data.extentionno ; 
		}
		if(g_AcdInfo.extNum  == 0 || g_AcdInfo.extNum =="0")
		{
	       alert("对不起，您还没有注册分机，请绑定话机后下次再试！");
	       return;
		}		 
		if(g_IsSipPhone )
		    cmsHelper.getServerInfo(onGetServerInfo) ;
		else
			cmsHelper.getServiceNode(onGetServiceNode,g_AcdInfo.extNum) ;	
		}
/********************************************
 * 获取服务器信息 * 
 * @param data
 *********************************************/
function onGetServerInfo(errcode,errmsg,data)
{
	if(errcode != "0"){
		showSubStatus("获取服务参数失败:"+errmsg); 
		return ;
	}		
	g_ServerInfo = data ;
	showSubStatus("注册webphone.. " );
	registSipPhone();	
	 setTimeout( function(){			 
		cmsHelper.getServiceNode(onGetServiceNode,g_AcdInfo.extNum) ;			 	  	    
	 },5000) ;	
	 
}

//取服务节点
function onGetServiceNode(errcode,errmsg,data)
{
	if(errcode != "0"){
		showSubStatus("获取服务参数失败:"+errmsg); 
		return ;
	}		
	g_ServerInfo.nodeid = data.nodeid ;
	g_ServerInfo.nodename = data.nodename ;
	g_ServerInfo.red5Url2 = data.red5Url2 ;
	g_ServerInfo.red5Url1 = data.red5Url1 ;
	if(data.phoneregist == 0)
	   {
			alert("您的分机:"+g_AcdInfo.extNum+"没注册到交换机，稍后如不能正常通话请检查话机网络!");
	   }
	showSubStatus("坐席注册.. " + g_ServerInfo.red5Url1);
	 
	FlashAgentX.loadConfig(g_AcdInfo.entId,g_AcdInfo.entPwd, g_ServerInfo.red5Url1 ,g_ServerInfo.red5Url2,g_AcdInfo.optId,g_AcdInfo.optPwd,g_AcdInfo.extNum) ;
	
	//setInterval("switchAcdAgent()",60000);	
}

function switchAcdAgent(){	
	cmsHelper.getServiceNode(onGetServerInfo4SwitchAcd,g_AcdInfo.extNum) ;	
}

function onGetServerInfo4SwitchAcd(errcode,errmsg,data)
{
	if(errcode != "0"){
		showSubStatus("GetServerInfo失败:"+errmsg); 
		return ;
	}		
	if(data.nodeid == g_ServerInfo.nodeid) {		 
		return ; 
	}
	g_ServerInfo.nodeid = data.nodeid ;
	g_ServerInfo.nodename = data.nodename ;
	g_ServerInfo.red5Url2 = data.red5Url2 ;
	g_ServerInfo.red5Url1 = data.red5Url1 ;
	showSubStatus("系统发现坐席话机已切换至" + g_ServerInfo.freeswitchIp +",现正将坐席电话条切换到相应acd，请稍后..."); 
	FlashAgentX.checkout() ;
	FlashAgentX.loadConfig(g_AcdInfo.entId,g_AcdInfo.entPwd, g_ServerInfo.red5Url1 ,g_ServerInfo.red5Url2,g_AcdInfo.optId,g_AcdInfo.optPwd,g_AcdInfo.extNum) ;
}
  

    function onCallState(state)
    { 	   
    	OnPlatCallState(state);
     try{
	    var now = new Date();
        var year = now.getFullYear();
        var month =(now.getMonth() + 1).toString();
        var day = (now.getDate()).toString();
        var hour= (now.getHours()).toString();
        var min = (now.getMinutes()).toString();
        var sec = (now.getSeconds()).toString();
        if (month.length == 1) {
            month = "0" + month;
        }
        if (day.length == 1) {
            day = "0" + day;
        }
        if (hour.length == 1) {
        	hour = "0" + hour;
        }
        if (min.length == 1) {
        	min = "0" + min;
        }
        if (sec.length == 1) {
        	sec = "0" + sec;
        }
        var dateTime = year+"-" + month+"-"  +  day+" "  +hour+":" +min+":" +sec;         
		var tmpDt =  {"callstate":state,"statetime":dateTime,"hostmillis": now.getTime()};
		onCallState0(tmpDt);
     }catch(err){
    	 //
     }
    }

	/***
	 * 状态更改回调函数，由flash控件内部调用
	 * @param state
	 *   0:签出,1:签入,2:上线,3:服务中与用户通话,4:置忙,5:保持,6:咨询坐席,7:咨询外线,8:三方通话,9:监听坐席，10插话座席，11上线忙
	 *    须新增 12 网络故障
	 *  功能：
	 *    当状态变更后，处理流程如下：
	 *      1. 更新callbanner 的状态输出
	 *      2. 调整callbanner的相应功能按钮状态（图片） 
	 */
   
	 
	
    function onCallState0( _state )
	{	  
		var stateStr=_state.callstate;
		callStateHelper.setCallState(_state.callstate);
		switch(_state.callstate)
		{
	     //该值为虚拟的状态，目的是首次启动时初始化所有的button  -2
		case callStateHelper.disconnect:  //-1, 未连接到服务器或连接失败
		{
			//基本功能区
			setButtonStyle("btn_onoff_line",0,1);
			setButtonStyle("btn_ready_busy",0,1);
			setButtonStyle("btn_callout",0,1);
			setButtonStyle("btn_hold_unhold",0,1);
			setButtonStyle("btn_login",0,0);
			setButtonStyle("btn_connect",0,0);  //随时可以连接其他 通信节点，因此全开	
			//高级功能	
			setButtonStyle("btn_consult",0,1);  //
			setButtonStyle("btn_transfer",0,1);  //咨询中允许转移咨询
			setButtonStyle("btn_confence",0,1);  //咨询中可以三方
			setButtonStyle("btn_toivr",0,1);  //咨询中可以三方
			//webrtc 功能
			setButtonStyle("btn_dtmf",0,1);
			setButtonStyle("btn_answer",0,1);
			setButtonStyle("btn_reject",0,1);
			setButtonStyle("btn_monitor",0,1);
			setButtonStyle("btn_stop_monitor",0,1);         
			setButtonStyle("btn_force_join",0,1);
			setButtonStyle("btn_whisper",0,1);
			setButtonStyle("btn_tokeover",0,1);
			setButtonStyle("btn_force_hungup",0,1);
			setButtonStyle("btn_monqueue",0,1);
			stateStr=("未连接");
			break;		
		}
		 
		case callStateHelper.logout:{  //已签出了， 显示可签入   显示基本通讯功能面板，且仅签入“按钮”可用
	
			setButtonStyle("btn_onoff_line",0,1);
			setButtonStyle("btn_ready_busy",0,1);
	
			setButtonStyle("btn_callout",0,1);
			setButtonStyle("btn_hold_unhold",0,1);
			setButtonStyle("btn_login",0,0);
			setButtonStyle("btn_connect",0,1);  //随时可以连接其他 通信节点，因此全开
			//禁用高级	
			setButtonStyle("btn_consult",0,1);  //咨询中允许停止咨询
			setButtonStyle("btn_transfer",0,1);  //咨询中允许转移咨询
			setButtonStyle("btn_confence",0,1);  //咨询中可以三方
			setButtonStyle("btn_ivr_auth",0,1);  //咨询中允许转移咨询
			setButtonStyle("btn_toivr",0,1);  //咨询中可以三方
			setButtonStyle("btn_connect",0,1);
			setButtonStyle("btn_monitor",0,1);
			setButtonStyle("btn_stop_monitor",0,1);         
			setButtonStyle("btn_force_join",0,1);
			setButtonStyle("btn_whisper",0,1);
			setButtonStyle("btn_tokeover",0,1);
			setButtonStyle("btn_force_hungup",0,1);
			setButtonStyle("btn_monqueue",0,1);
			stateStr=("签出");
			break;		
		} 	
		case callStateHelper.login:{  //已签入， 可电话了	  显示基本通讯功能面板，
			var skill_monitor1 = document.getElementById("skill_monitor");
			if(FlashAgentX.agentRole=="1" || FlashAgentX.agentRole=="2"){
				skill_monitor1.style.display = "block";
			}else{
				skill_monitor1.style.display = "none";
			}
			setButtonStyle("btn_onoff_line",0,0);
			setButtonStyle("btn_ready_busy",0,0);	
			setButtonStyle("btn_callout",0,0);
			setButtonStyle("btn_hold_unhold",0,1);
			setButtonStyle("btn_login",1,0);
			setButtonStyle("btn_connect",0,1);  //随时可以连接其他 通信节点，因此全开			
			//保持时可以干别的		
			setButtonStyle("btn_consult",0,1);  //无通话的咨询 =坐席间通话
			setButtonStyle("btn_transfer",0,1);  //咨询中允许转移咨询
			setButtonStyle("btn_confence",0,1);  //咨询中可以三方
			setButtonStyle("btn_toivr",0,1);  //咨询中可以三方
			setButtonStyle("btn_monitor",0,0);
			setButtonStyle("btn_stop_monitor",0,1);         
			setButtonStyle("btn_force_join",0,1);
			setButtonStyle("btn_whisper",0,1);
			setButtonStyle("btn_tokeover",0,1);
			setButtonStyle("btn_force_hungup",0,1);
			setButtonStyle("btn_monqueue",0,0);
			stateStr=("签入");
			break;		
		} 
		case callStateHelper.online:{  //2 上线 ， 可电话了	 
			setButtonStyle("btn_onoff_line",1,0);
			setButtonStyle("btn_ready_busy",0,0);	
			setButtonStyle("btn_callout",0,0);
			setButtonStyle("btn_hold_unhold",0,1);
			setButtonStyle("btn_login",1,0);
			setButtonStyle("btn_connect",0,1);  //随时可以连接其他 通信节点，因此全开
			setButtonStyle("btn_consult",0,1);  //咨询中允许停止咨询
			setButtonStyle("btn_transfer",0,1);  //咨询中允许转移咨询
			setButtonStyle("btn_confence",0,1);  //咨询中可以三方
			setButtonStyle("btn_toivr",0,1);  //咨询中可以三方
			setButtonStyle("btn_monitor",0,0);
			setButtonStyle("btn_stop_monitor",0,1);         
			setButtonStyle("btn_force_join",0,1);
			setButtonStyle("btn_whisper",0,1);
			setButtonStyle("btn_tokeover",0,1);
			setButtonStyle("btn_force_hungup",0,1);
			setButtonStyle("btn_monqueue",0,0);
			stateStr=("上线");
			break;		
		} 	
		case callStateHelper.using:{  //30 ，电话中	 
			setButtonEnable("btn_onoff_line",1);
			setButtonEnable("btn_ready_busy",1);
			setButtonStyle("btn_callout",1,0);
			setButtonStyle("btn_hold_unhold",0,1);
			setButtonStyle("btn_login",1,1);
			setButtonStyle("btn_connect",0,1);
 			setButtonStyle("btn_consult",0,1);  //咨询中允许停止咨询
			setButtonStyle("btn_transfer",0,1);  //咨询中允许转移咨询
 			setButtonStyle("btn_confence",0,1);  //咨询中可以三方
 			setButtonStyle("btn_toivr",0,1);  //咨询中可以三方
 			setButtonStyle("btn_monitor",0,1);
			setButtonStyle("btn_stop_monitor",0,1);         
			setButtonStyle("btn_force_join",0,1);
			setButtonStyle("btn_whisper",0,1);
			setButtonStyle("btn_tokeover",0,1);
			setButtonStyle("btn_force_hungup",0,1);
			setButtonStyle("btn_monqueue",0,0);
 			stateStr=("工作");
			break;		
		} 
		case callStateHelper.talking:{  //3 ，电话中	 
			setButtonEnable("btn_onoff_line",1);
			setButtonEnable("btn_ready_busy",1);
 			setButtonStyle("btn_callout",1,0);			
			setButtonStyle("btn_hold_unhold",0,0);
			setButtonStyle("btn_login",1,1);
			setButtonStyle("btn_connect",0,1);
 			setButtonStyle("btn_consult",0,0);  //咨询中允许停止咨询
			setButtonStyle("btn_transfer",0,1);  //咨询中允许转移咨询
 			setButtonStyle("btn_confence",0,1);  //咨询中可以三方
 			setButtonStyle("btn_toivr",0,0);  //咨询中可以三方
 			setButtonStyle("btn_monitor",0,1);
			setButtonStyle("btn_stop_monitor",0,1);         
			setButtonStyle("btn_force_join",0,1);
			setButtonStyle("btn_whisper",0,1);
			setButtonStyle("btn_tokeover",0,1);
			setButtonStyle("btn_force_hungup",0,1);
			setButtonStyle("btn_monqueue",0,0);
 			stateStr=("通话");
			break;		
		} 	
		case callStateHelper.busy:
		case callStateHelper.busylogin:
		case callStateHelper.busyrest: 
		case callStateHelper.busyonline201:
		{
			setButtonStyle("btn_onoff_line",0,0);
			setButtonStyle("btn_ready_busy",1,0);	
			setButtonStyle("btn_callout",0,0);
			setButtonStyle("btn_hold_unhold",0,1);
			setButtonStyle("btn_login",1,0);
			setButtonStyle("btn_connect",0,1);  //随时可以连接其他 通信节点，因此全开			
 			setButtonStyle("btn_consult",0,1);  //咨询中允许停止咨询
			setButtonStyle("btn_transfer",0,1);  //咨询中允许转移咨询
			setButtonStyle("btn_confence",0,1);  //咨询中可以三方
 			setButtonStyle("btn_toivr",0,1);  //咨询中可以三方
 			setButtonStyle("btn_monitor",0,1);
			setButtonStyle("btn_stop_monitor",0,1);         
			setButtonStyle("btn_force_join",0,1);
			setButtonStyle("btn_whisper",0,1);
			setButtonStyle("btn_tokeover",0,1);
			setButtonStyle("btn_force_hungup",0,1);
			setButtonStyle("btn_monqueue",0,0);
 			stateStr=("小休");
			break;		
		} 
	
		case callStateHelper.hold:{  //保持
			setButtonEnable("btn_onoff_line",1);
			setButtonEnable("btn_ready_busy",1);	
			setButtonStyle("btn_callout",1,0);  //hold客户
			//setButtonStyle("btn_callout",0,1);
			setButtonStyle("btn_hold_unhold",1,0);
			setButtonStyle("btn_login",1,1);
			setButtonStyle("btn_connect",0,1);  //随时可以连接其他 通信节点，因此全开			
 			setButtonStyle("btn_consult",0,0);  //咨询中允许停止咨询
			setButtonStyle("btn_transfer",0,1);  //咨询中允许转移咨询
			setButtonStyle("btn_confence",0,1);  //咨询中可以三方
 			setButtonStyle("btn_toivr",0,0);  //咨询中可以三方
 			setButtonStyle("btn_monitor",0,1);
			setButtonStyle("btn_stop_monitor",0,1);         
			setButtonStyle("btn_force_join",0,1);
			setButtonStyle("btn_whisper",0,1);
			setButtonStyle("btn_tokeover",0,1);
			setButtonStyle("btn_force_hungup",0,1);
			setButtonStyle("btn_monqueue",0,0);
 			stateStr=("保持");
			break;		
		} 
		//咨询内线中 ， 
		case callStateHelper.consultagc:{  
			setButtonStyle("btn_hold_unhold",1,1);
			setButtonStyle("btn_consult",1,0);  //咨询中允许停止咨询
			setButtonStyle("btn_transfer",0,0);  //咨询中允许转移咨询
			setButtonStyle("btn_confence",0,0);  //btn_confence 0=内三方，1=开始外三，2=结束内三方，3=结束外三	 
			setButtonStyle("btn_callout",1,1);  //hold客户		
  			setButtonStyle("btn_toivr",0,1);  //咨询中可以三方
  			setButtonStyle("btn_monitor",0,1);
			setButtonStyle("btn_stop_monitor",0,1);         
			setButtonStyle("btn_force_join",0,1);
			setButtonStyle("btn_whisper",0,1);
			setButtonStyle("btn_tokeover",0,1);
			setButtonStyle("btn_force_hungup",0,1);
			setButtonStyle("btn_monqueue",0,0);
	 		stateStr=("咨询");
			break;		
		} 
		//外线咨询中
		case callStateHelper.consultuser:{  //咨询内线中
			setButtonStyle("btn_hold_unhold",1,1);
			//setButtonStyle("btn_callout",0,1);
			setButtonStyle("btn_callout",1,1);  //hold客户
			setButtonStyle("btn_consult",2,0);  // 可以退出外线咨询
			setButtonStyle("btn_transfer",1,0);  //转外线咨询席
			setButtonStyle("btn_confence",1,0);  //咨询中可以三方 btn_confence 0=内三方，1=开始外三，2=结束内三方，3=结束外三			
 	 		setButtonStyle("btn_toivr",0,1);  //咨询中可以三方
 	 		setButtonStyle("btn_monitor",0,1);
			setButtonStyle("btn_stop_monitor",0,1);         
			setButtonStyle("btn_force_join",0,1);
			setButtonStyle("btn_whisper",0,1);
			setButtonStyle("btn_tokeover",0,1);
			setButtonStyle("btn_force_hungup",0,1);
			setButtonStyle("btn_monqueue",0,0);
	 			stateStr=("咨询");
			break;		
		} 
		//咨询振铃
		case callStateHelper.ring3:{  //咨询内线中
			setButtonStyle("btn_hold_unhold",1,1);
			setButtonStyle("btn_callout",1,1);  //hold客户
			//setButtonStyle("btn_callout",0,1);
			setButtonStyle("btn_consult",2,0);  // 可以退出外线咨询
			setButtonStyle("btn_transfer",1,1);  //转外线咨询席
			setButtonStyle("btn_confence",1,1);  //咨询中可以三方 btn_confence 0=内三方，1=开始外三，2=结束内三方，3=结束外三			
 	 		setButtonStyle("btn_toivr",0,1);  //咨询中可以三方
 	 		setButtonStyle("btn_monitor",0,1);
			setButtonStyle("btn_stop_monitor",0,1);         
			setButtonStyle("btn_force_join",0,1);
			setButtonStyle("btn_whisper",0,1);
			setButtonStyle("btn_tokeover",0,1);
			setButtonStyle("btn_force_hungup",0,1);
			setButtonStyle("btn_monqueue",0,0);
	 		stateStr=("咨询");
			break;		
		} 
		
		case callStateHelper.conference:{
			setButtonStyle("btn_hold_unhold",0,1);
			setButtonStyle("btn_callout",1,1);  //hold客户
			setButtonStyle("btn_login",1,0);
			//setButtonStyle("btn_callout",0,1);
			setButtonStyle("btn_consult",0,1);
			setButtonStyle("btn_transfer",0,1);  
			setButtonStyle("btn_confence",2,0); //会议中，btn_confence 0=内三方，1=开始外三，2=结束内三方，3=结束外三	
 	 		setButtonStyle("btn_toivr",0,1);  //咨询中可以三方	
 	 		setButtonStyle("btn_monitor",0,1);
			setButtonStyle("btn_stop_monitor",0,1);         
			setButtonStyle("btn_force_join",0,1);
			setButtonStyle("btn_whisper",0,1);
			setButtonStyle("btn_tokeover",0,1);
			setButtonStyle("btn_force_hungup",0,1);
			setButtonStyle("btn_monqueue",0,0);
			stateStr=("咨询");
			break;		
		} 
	
		case callStateHelper.monitor:{  //9  监听
			setButtonStyle("btn_onoff_line",0,1);
			setButtonStyle("btn_ready_busy",0,1);	
			setButtonStyle("btn_callout",1,1);
			//setButtonStyle("btn_callout",0,1);
			setButtonStyle("btn_hold_unhold",0,1);
			setButtonStyle("btn_login",1,0);
			setButtonStyle("btn_connect",0,0);  //随时可以连接其他 通信节点，因此全开
 			setButtonStyle("btn_consult",0,1);  //咨询中允许停止咨询
			setButtonStyle("btn_transfer",0,1);  //咨询中允许转移咨询
			setButtonStyle("btn_confence",0,1);  //咨询中可以三方
  			setButtonStyle("btn_toivr",0,1);  //咨询中可以三方
  			setButtonStyle("btn_monitor",0,1);  //监听
			setButtonStyle("btn_stop_monitor",0,0);    //停止监听     
			setButtonStyle("btn_force_join",0,0);  //强插
			setButtonStyle("btn_whisper",0,0);  //耳语
			setButtonStyle("btn_tokeover",0,0);  //拦截
			setButtonStyle("btn_force_hungup",0,0); //强拆
			setButtonStyle("btn_monqueue",0,0);
	 			stateStr=("监听");
			break;		
		}  
		case callStateHelper.insert:{  //10	 强插 		 
			setButtonStyle("btn_onoff_line",0,1);
			//setButtonStyle("btn_ready_busy",0,1);	
			setButtonStyle("btn_callout",1,1);
			setButtonStyle("btn_callout",0,1);
			setButtonStyle("btn_hold_unhold",0,1);
			setButtonStyle("btn_login",1,0);
			setButtonStyle("btn_connect",0,0);  //随时可以连接其他 通信节点，因此全开
	 		//setButtonStyle("btn_consult",0,1);  //咨询中允许停止咨询
			setButtonStyle("btn_transfer",0,1);  //咨询中允许转移咨询
			setButtonStyle("btn_confence",0,1);  //咨询中可以三方
 	 		setButtonStyle("btn_toivr",0,1);  //咨询中可以三方
 	 		setButtonStyle("btn_monitor",0,1);  //监听
			setButtonStyle("btn_stop_monitor",0,1);    //停止监听     
			setButtonStyle("btn_force_join",1,0);  //强插
			setButtonStyle("btn_whisper",0,1);  //耳语
			setButtonStyle("btn_tokeover",0,1);  //拦截
			setButtonStyle("btn_force_hungup",0,1); //强拆
			setButtonStyle("btn_monqueue",0,0);
	 		stateStr=("插话");
			break;		
		} 
		case callStateHelper.whisper:{  //13 耳语	 		 
			setButtonStyle("btn_onoff_line",0,1);
			setButtonStyle("btn_ready_busy",0,1);	
			setButtonStyle("btn_callout",1,1);
			setButtonStyle("btn_hold_unhold",0,1);
			setButtonStyle("btn_login",1,0);
			setButtonStyle("btn_connect",0,1);  //随时可以连接其他 通信节点，因此全开
			//禁用高级	
			setButtonStyle("btn_consult",0,1);  //咨询中允许停止咨询
			setButtonStyle("btn_transfer",0,1);  //咨询中允许转移咨询
			setButtonStyle("btn_confence",0,1);  //咨询中可以三方
 			setButtonStyle("btn_toivr",0,1);  //咨询中可以三方
 			setButtonStyle("btn_monitor",0,1);  //监听
			setButtonStyle("btn_stop_monitor",0,1);    //停止监听     
			setButtonStyle("btn_force_join",0,1);  //强插
			setButtonStyle("btn_whisper",1,0);  //耳语
			setButtonStyle("btn_tokeover",0,1);  //拦截
			setButtonStyle("btn_force_hungup",0,1); //强拆
			setButtonStyle("btn_monqueue",0,0);
 			stateStr=("耳语");
			break;		
		} 
		case callStateHelper.robcall:{  //13 耳语	 		 
			setButtonStyle("btn_onoff_line",0,1);
			setButtonStyle("btn_ready_busy",0,1);	
			setButtonStyle("btn_callout",1,1);
			setButtonStyle("btn_hold_unhold",0,1);
			setButtonStyle("btn_login",1,0);
			setButtonStyle("btn_connect",0,1);  //随时可以连接其他 通信节点，因此全开
			//禁用高级	
			setButtonStyle("btn_consult",0,1);  //咨询中允许停止咨询
			setButtonStyle("btn_transfer",0,1);  //咨询中允许转移咨询
			setButtonStyle("btn_confence",0,1);  //咨询中可以三方
 			setButtonStyle("btn_toivr",0,1);  //咨询中可以三方
 			setButtonStyle("btn_monitor",0,1);  //监听
			setButtonStyle("btn_stop_monitor",0,1);    //停止监听     
			setButtonStyle("btn_force_join",0,1);  //强插
			setButtonStyle("btn_whisper",0,1);  //耳语
			setButtonStyle("btn_tokeover",1,0);  //拦截
			setButtonStyle("btn_force_hungup",0,1); //强拆
			setButtonStyle("btn_monqueue",0,0);
 			stateStr=("拦截");
			break;		
		} 
		
		case callStateHelper.busyonline:
		case callStateHelper.busy211:
		case callStateHelper.busyonlinerest:
		case callStateHelper.busyonlinelogin:
		{  //11 上线 忙	 
			setButtonStyle("btn_onoff_line",1,0);
			setButtonStyle("btn_ready_busy",1,0);
			setButtonStyle("btn_callout",0,0);
			setButtonStyle("btn_hold_unhold",0,1);
			setButtonStyle("btn_toivr",0,1);
			setButtonStyle("btn_login",1,0);
			setButtonStyle("btn_connect",0,0);  //随时可以连接其他 通信节点，因此全开
			setButtonStyle("btn_consult",0,1);  //咨询中允许停止咨询
			setButtonStyle("btn_transfer",0,1);  //咨询中允许转移咨询
			setButtonStyle("btn_confence",0,1);  //咨询中可以三方
 			setButtonStyle("btn_toivr",0,1);  //咨询中可以三方
 			setButtonStyle("btn_monqueue",0,0);
 			stateStr=("小休"); 
			break;		
		} 
		case callStateHelper.callcusting:
		case callStateHelper.ring:{  //12  呼出振铃	 
			setButtonEnable("btn_onoff_line",1);
			setButtonEnable("btn_ready_busy",1);
			setButtonStyle("btn_callout",1,0);   //通话中，可以发送 dtmf 信号
			//setButtonStyle("btn_callout",0,1);
			setButtonStyle("btn_consult",0,1);  //咨询中允许停止咨询
			setButtonStyle("btn_hold_unhold",0,1);
			setButtonStyle("btn_toivr",0,1);
			setButtonStyle("btn_login",1,1);
			setButtonStyle("btn_connect",0,1);  
			setButtonStyle("btn_monitor",0,1);  //监听
			setButtonStyle("btn_stop_monitor",0,1);    //停止监听     
			setButtonStyle("btn_force_join",0,1);  //强插
			setButtonStyle("btn_whisper",0,1);  //耳语
			setButtonStyle("btn_tokeover",0,1);  //拦截
			setButtonStyle("btn_force_hungup",0,1); //挂断
			setButtonStyle("btn_monqueue",0,0);
			stateStr=("振铃");
			break;		
		}
		case callStateHelper.agctalk:{  //14 坐席电话，只有挂机	 
			setButtonEnable("btn_onoff_line",1);
			setButtonEnable("btn_ready_busy",1);
	  //启用挂机
			//setButtonStyle("btn_callout",0,1);
			setButtonStyle("btn_callout",1,0);			
			setButtonStyle("btn_hold_unhold",0,1);
			setButtonStyle("btn_login",1,1);
			setButtonStyle("btn_connect",0,1);
			//保持时可以干别的		
			setButtonStyle("btn_consult",0,1);  //咨询中允许停止咨询
			setButtonStyle("btn_transfer",0,1);  //咨询中允许转移咨询
 			setButtonStyle("btn_confence",0,1);  //咨询中可以三方
 			setButtonStyle("btn_toivr",0,1);  //咨询中可以三方
 			setButtonStyle("btn_monitor",0,1);  //监听
			setButtonStyle("btn_stop_monitor",0,1);    //停止监听     
			setButtonStyle("btn_force_join",0,1);  //强插
			setButtonStyle("btn_whisper",0,1);  //耳语
			setButtonStyle("btn_tokeover",0,1);  //拦截
			setButtonStyle("btn_force_hungup",0,1); //挂断
			setButtonStyle("btn_monqueue",0,0);
 			stateStr=("坐席间通话");
			break;		
		} 
	}
		showCStateMsg(_state) ;
	 		 
	}
	 
	 
	/**********************************************
	 * 隐式设置按钮样式
	 *  调用者不确定按钮应该显示具体功能，只想将其禁用或启用
	 * @param id      按钮对应id
	 * @param enable  0 ：可用， 1：不可用
	 */
	function getButtonEnable(obj)
	{
		if(obj == null){			 
			return false;
		}
		if(obj.value >= 10 ){  showSubStatus("操作无效!"); return false ;}	
		else return true ;	
	}
	/**********************************************
	 * 隐式设置按钮样式
	 *  调用者不确定按钮应该显示具体功能，只想将其禁用或启用
	 * @param id      按钮对应id
	 * @param enable  0 ：可用， 1：不可用
	 */
	function setButtonEnable(id,enable)
	{
		var tmpObj = document.getElementById(id);
		if(tmpObj == null){
			return ;
		}
		setButtonStyle(id,tmpObj.fun_value,enable) ;	
	}
	
	function state0(){
	    $('#msg1').css('display','block');
	}
	function doSome(){
	 	   // alert("ace_main doSome");
	         var  sel_busy1= document.getElementById("sel_busy1");
	         var index=sel_busy1.selectedIndex;
	         var Text=sel_busy1.options[index].text;
	         var various=document.getElementById("various");
	         various.innerHTML=Text;
	         $('#msg1').css('display','none');
	 } 
	 
	 function staclose(){
	 	   $('#msg1').css('display','none');
	 }
	 
	 function sivrclose(){
	 	   $('#msgivr1').css('display','none');
	 }
	 
	 function showivrflow1(){
	    $('#msgivr1').css('display','block');
	 }
	 
	 function selivr1(){
	 	 showivrflow1();
	 }
	 function transflow1(){
	 	 var flowtype=document.getElementById("sel_ivr1");
	 	 var sToIvr = "";
	 	 if(FlashAgentX.g_callEvent !=null){
	 	 	  sToIvr = FlashAgentX.g_callEvent.callid + "," + g_AcdInfo.entId + "," + g_AcdInfo.qId + "," + g_AcdInfo.optId;
	 	 }
	 	 var ivrdata1=document.getElementById("ivrdata1");
	 	 var main1=document.getElementById("ivrmainid1");
	 	 var sub1=document.getElementById("ivrsubid1");
	 	 if(main1==null || main1.value==''){
	 	    alert("IVR主流程不能为空");
	 	    return false;
	 	 }
	 	 if(sub1==null || sub1.value==''){
	 	    alert("IVR子流程不能为空");
	 	    return false;
	 	 }
	 	 if(flowtype.value=="auth"){
	 	 	 if(ivrdata1==null || ivrdata1.value==''){
	 	 	 	 alert("鉴权必须传随路数据，请填写");
	 	 	 	 return false;
	 	 	 }
	 	 }
	 	 if(ivrdata1==null || ivrdata1.value==''){
	 	    
	   }else{
	   	  sToIvr = sToIvr+","+ivrdata1.value;
	   }
	   FlashAgentX.gotoivr(flowtype.value,main1.value, sub1.value, sToIvr);
     showSubStatus && showSubStatus("FlashAgentX.gotoivr  "+ sToIvr);
     sivrclose();
	 }
	  //doSome(); 
	// $('#box1>.f1').click(function(){
	//         $('#msg1').css('display','none');
	 //    })
	 function btnCall(){
	             if($('table.table_num').css('display')=='none'){
	                 $('table.table_num').css('display','block');
	             }else{
	                  $('table.table_num').css('display','none');
	             }
	 }
	 function dialUp(num){
      var telnumber = document.all("telnumber").value;
      var telnumber = telnumber + num; 
      document.all("telnumber").value = telnumber; 
      document.all("telnumber").focus(); 
   }
   function phoneback(){
		  var inObj = document.all("telnumber");
		  inObj.value= inObj.value.substring(0, inObj.value.length - 1);
	 }
	 
	 function phonecancel(){
	    document.all("telnumber").value="";
	    document.getElementById("table_num").style.display="none";
   } 
   
   function phoneensure(){
	var telnumber=document.all("telnumber").value;
	if(telnumber==""){
		 window.alert("电话号码不能为空！");
		 return;
	}
     console.info("ensure()",telnumber);
    var btn_callout = document.getElementById("btn_callout");
	if (!getButtonEnable(btn_callout)) return;
    switch (btn_callout.fun_value) {
        case 0: { //呼出前的拨号盘控制
             if( ! getButtonEnable(btn_callout)) return ;
             switch(btn_callout.fun_value)
             {
				case 0:{ //呼出前的拨号盘控制
                    var tmpObj = document.getElementById("dialout_input") ;					   
                    if(tmpObj!=null && tmpObj.value !=""){
					//	  alert("测试用，接入crm需 onbeforecall_58  " + tmpObj.value );
                   //   if( onbeforecall_58) onbeforecall_58(tmpObj.value) ; 
                    //  else
                        FlashAgentX.makecall(tmpObj.value,"");
                    }else{					    
                      showSubStatus("请输入电话!");					
                       break; 
                    }
				}					
              case 1:{  FlashAgentX.dropcall();break ;}  
             }		 			 
             break ;
        }
        case 1:{ FlashAgentX.dropcall(); break; }
    }
    document.getElementById("table_num").style.display="none";	
}  
	/**********************************************
	  * 显式设置按钮样式
	  * @param id      按钮对应id
	  * @param subFunc 按钮子功能（当功能按钮0，复合功能按钮1,2,3）
	  *    subFunc 对应button中的value，该值可实现功能包括：
	  *      1.复合按钮中各个功能项
	  *      2.决定改按钮是否被拦截，拦截办法 value >10 表示拦截，
	  *    
	  * @param enable  0 ：可用， 1：不可用
	  */
	function setButtonStyle(id,subFunc,enable)
	{
		//if( g_Button_Icon_Text != "text" )setButtonIcon(id,subFunc,enable) ;else
			
			////setButtonText(id,subFunc,enable) ;	
			setButtonIcon(id,subFunc,enable);	
	}	
	
	function setButtonIcon(id,subFunc,enable)
	{	
		//alert(id+""+subFunc+""+enable);
		var tmpObj = document.getElementById(id);
		if(tmpObj == null){
		//	showSubStatus(id +"未定义...")
			return ;
		}
		//检查系统禁用方式，隐藏则直接修改display
		var tmpStr = "#"+ id+" img" ;
		 if( g_DisEnableBtnStyle == "hidden"){
			 if(enable == 1) //禁用
				{ 
				  tmpObj.fun_value  = parseInt(subFunc) + 10 ;  //禁用
				  tmpObj.style.display = "none";
				  return ;
				}else{ 
				  tmpObj.fun_value  = parseInt(subFunc) ;  //可用
				  tmpObj.style.display = "block";
				  $(tmpStr).css("cursor","pointer")  ; 
				}
		 }else{
			 //采用灰色icon 表现禁用icon方式		 
				if(enable == 1)
					{ 
					  tmpObj.fun_value  = parseInt(subFunc) + 10 ;  //禁用
				      $(tmpStr).css("cursor","not-allowed")  ;
					}else{ 
					  tmpObj.fun_value  = parseInt(subFunc) ;  //可用
					  $(tmpStr).css("cursor","pointer")  ; 
					}				 
		 }
	   switch(id)
	   {
		   case "btn_onoff_line": {
			   if(subFunc == 0){  //上线
				   $("#btn_onoff_line img").attr({title:"上线",src:g_ImgPath+"/btn_online_"+enable+".png"});
					$("#btn_onoff_line span").html('上线');
			   }else{
				   $("#btn_onoff_line img").attr({title:"下线",src:g_ImgPath+"/btn_offline_"+enable+".png"});
					$("#btn_onoff_line span").html('下线');
			   }break ;
		   } 
		   /*case "btn_ready_busy": {
			   if(subFunc == 0){  //上线
				   $("#btn_ready_busy img").attr({title:"小休",src:g_ImgPath+"/btn_busy_"+enable+".png"});
			   }else{
				   $("#btn_ready_busy img").attr({title:"就绪",src:g_ImgPath+"/btn_ready_"+enable+".png"});
			   }break ;
		   } */


		   case "btn_ready_busy": {
			   if(subFunc == 0){  //上线
				   $("#btn_ready_busy img").attr({title:"状态",src:g_ImgPath+"/btn_state_"+enable+".png"});
				   // $("#btn_ready_busy span).html('状态');
			   }else{
				   $("#btn_ready_busy img").attr({title:"状态",src:g_ImgPath+"/btn_state_"+enable+".png"});
				   //$("#btn_ready_busy span).html('状态');
			   }break ;
		   } 


		   case "btn_callout": {  
				   if(subFunc == 0) { //上线
					   $("#btn_callout img").attr({title:"呼出",src:g_ImgPath+"/btn_callout_"+enable+".png"});
					   $("#btn_callout span").html('呼出');
				   }else{
					   $("#btn_callout img").attr({title:"挂机",src:g_ImgPath+"/btn_hungup_"+enable+".png"});
					   $("#btn_callout span").html('挂机');
				   }break ;			   
	       } 
	 	   case "btn_hold_unhold": {
			   if(subFunc == 0){  //上线
				   $("#btn_hold_unhold img").attr({title:"保持",src:g_ImgPath+"/btn_hold_"+enable+".png"});
				   $("#btn_hold_unhold span").html('保持');
			   }else{
				   $("#btn_hold_unhold img").attr({title:"恢复",src:g_ImgPath+"/btn_unhold_"+enable+".png"});
				   $("#btn_hold_unhold span").html('恢复');
			   }break ;
	       } 
		   case "btn_toivr": {
			   $("#btn_toivr img").attr({title:"转ivr",src:g_ImgPath+"/btn_toivr_"+enable+".png"});
			   $("#btn_toivr span").html('转调查');
		       break ;
	       } 
	
		   /*case "btn_music": {
			   $("#btn_music img").attr({title:"放音",src:g_ImgPath+"/btn_music_"+enable+".png"});
		       break ;
	       } 
		   case "btn_stop_music": {
			   $("#btn_stop_music img").attr({title:"停止放音",src:g_ImgPath+"/btn_stop_music_"+enable+".png"});
		       break ;
	       } 
		   case "btn_ivr_auth": {
			   $("#btn_ivr_auth img").attr({title:"IVR鉴权",src:g_ImgPath+"/btn_ivrauth_"+enable+".png"});
		       break ;
	       }*/
		   case "btn_login": {
			   if(subFunc == 0){  //上线 
				   $("#btn_login img").attr({title:"签入",src:g_ImgPath+"/btn_login_"+enable+".png"});
				   $("#btn_login span").html('签入');
			    }else{
				   $("#btn_login img").attr({title:"签出",src:g_ImgPath+"/btn_logout_"+enable+".png"});
				   $("#btn_login span").html('签出');
			    }break ;
	       }
	
		   /*case "btn_connect": {
			   $("#btn_connect img").attr({title:"重连通信服务器",src:g_ImgPath+"/btn_connect_"+enable+".png"});
		       break ;
	       }*/
		   case "btn_consult": {  
			   if(subFunc == 0){  //发起咨询 
				   $("#btn_consult img").attr({title:"咨询",src:g_ImgPath+"/btn_consult_"+enable+".png"});   //发起咨询
				   $("#btn_consult span").html('咨询');
			   }else if(subFunc == 1){  
				   $("#btn_consult img").attr({title:"结束咨询",src:g_ImgPath+"/btn_stop_consult_agc_"+enable+".png"}); //停止内线咨询
				   $("#btn_consult span").html('结束咨询');
			   }else {
				   $("#btn_consult img").attr({title:"结束咨询",src:g_ImgPath+"/btn_stop_consult_out_"+enable+".png"});  //停止外线咨询
				   $("#btn_consult span").html('结束咨询');
			   }break ;
	       }
		   case "btn_confence": {  //btn_confence 0=内三方，1=开始外三，2=结束内三方，3=结束外三	
			   if(subFunc == 0){  //内三方 
				   $("#btn_confence img").attr({title:"三方通话",src:g_ImgPath+"/btn_confence_"+enable+".png"});
				    $("#btn_confence span").html('三方');
			   }else   if(subFunc == 1){ //外三方 
				   $("#btn_confence img").attr({title:"三方通话",src:g_ImgPath+"/btn_confence_"+enable+".png"});
				   $("#btn_confence span").html('三方');
			   }else{  //停止三方，接回电话
				   $("#btn_confence img").attr({title:"接回",src:g_ImgPath+"/btn_stop_confence_"+enable+".png"});
				   $("#btn_confence span").html('三方');
		       }break ;
	       }	   
		   //转坐席， 1 转外线咨询
		   case "btn_transfer": {  
			   if(subFunc == 0){  //内三方 
			       $("#btn_transfer img").attr({title:"转坐席",src:g_ImgPath+"/btn_trans_agc_"+enable+".png"});
			       $("#btn_transfer span").html('转坐席');
			   }else{
				   $("#btn_transfer img").attr({title:"转移外线",src:g_ImgPath+"/btn_trans_out_"+enable+".png"});
				   $("#btn_transfer span").html('转移外线');  
		       }break ;
	       }
		   //组长席功能
		   case "btn_monitor": {
				   $("#btn_monitor img").attr({title:"监听",src:g_ImgPath+"/btn_monitor_"+enable+".png"});
				    $("#btn_monitor span").html('监听');
		       break ;
	       }
		   case "btn_stop_monitor": {
				   $("#btn_stop_monitor img").attr({title:"结束监听",src:g_ImgPath+"/btn_stop_monitor_"+enable+".png"});
				   $("#btn_stop_monitor span").html('结束监听');
		       break ;
	       }
		   case "btn_force_join": {
			   if(subFunc == 0){   
				   $("#btn_force_join img").attr({title:"插话",src:g_ImgPath+"/btn_join_"+enable+".png"});
				   $("#btn_force_join span").html('插话');
			   }else{
				   $("#btn_force_join img").attr({title:"退出插话",src:g_ImgPath+"/btn_stop_join_"+enable+".png"}); 
				    $("#btn_force_join span").html('退出插话');
		       }break ;
	       }
		   case "btn_whisper": {
			   if(subFunc == 0){   
				   $("#btn_whisper img").attr({title:"耳语",src:g_ImgPath+"/btn_whisper_"+enable+".png"});
				    $("#btn_whisper span").html('耳语');
			   }else{
				   $("#btn_whisper img").attr({title:"退出耳语",src:g_ImgPath+"/btn_stop_whisper_"+enable+".png"});
				   $("#btn_whisper span").html('退出耳语'); 
		       }break ;
	       }
		   
		   
		   case "btn_tokeover": {
			   if(subFunc == 0){
			      $("#btn_tokeover img").attr({title:"强接",src:g_ImgPath+"/btn_takeover_"+enable+".png"});
			      $("#btn_tokeover span").html('强接'); 
		          break ;
	          }
	       else{
	          $("#btn_callout img").attr({title:"挂机",src:g_ImgPath+"/btn_hungup_"+enable+".png"});
					  $("#btn_callout span").html('挂机');
	       }
	     }
		   case "btn_force_hungup": {
			   $("#btn_force_hungup img").attr({title:"强拆",src:g_ImgPath+"/btn_force_hungup_"+enable+".png"});
			   $("#btn_force_hungup span").html('强拆');
		       break ;
	       }
		   case "btn_monqueue": {
			   if(subFunc == 0){  //上线
				   $("#btn_monqueue img").attr({title:"队列",src:g_ImgPath+"/btn_monqueue_"+enable+".png"});
				   $("#btn_monqueue span").html('队列');
			   }else{
				   $("#btn_monqueue img").attr({title:"队列",src:g_ImgPath+"/btn_monqueue_"+enable+".png"});
				   $("#btn_monqueue span").html('队列');
			   }break ;
	       } 
		   case "btn_force_login": {
			  $("#btn_force_login img").attr({title:"代签入",src:g_ImgPath+"/btn_force_login_"+enable+".png"});
			   break ;
	       }
		   case "btn_force_logout": {
	  	       $("#btn_force_logout img").attr({title:"代签出",src:g_ImgPath+"/btn_force_logout_"+enable+".png"});
			   break ;
	       }
	
		   /*下面是 webrtc phone 的状态变更*/	   
		   /*case "btn_answer": {
			       $("#btn_answer img").attr({title:"应答",src:g_ImgPath+"/btn_answer_"+enable+".png"});
			   break ;
		   }
		   case "btn_dtmf": {  
			   $("#btn_dtmf img").attr({title:"发送DTMF",src:g_ImgPath+"/btn_dtmf_"+enable+".png"});
		       break ;
		   } 
		   //sip 话机 拒绝 
		   case "btn_reject": {  		   
				   $("#btn_reject img").attr({title:"拒绝",src:g_ImgPath+"/btn_reject_"+enable+".png"});
			   break ;			   
		   } */
	       //状态指示灯  ：0 未连接 红色，1连接未主持 灰色，2已经主持蓝色， 3 建立媒体流 绿色 
		   case "btn_sip_sleep": {  	
			   var sleepmsg = ["sip连接已断开，点击可重新开启","sip未注册，点击注册","sip已注册成功!","通话中，挂机？"];
			   $("#btn_sip_sleep img").attr({title:sleepmsg[subFunc],src:g_ImgPath+"/cbphonesleep_"+subFunc+".png"});
			   break ;			   
		   } 
	   }
	} 	
	
	/*****************************
	 * 设置按钮样式 -- 文字方式
	 * @param id
	 * @param subFunc
	 * @param enable
	 ****************************/
	function setButtonText(id,subFunc,enable)
	{	
		var tmpObj = document.getElementById(id);
		if(tmpObj == null){
		//	showSubStatus(id +"未定义...")
			return ;
		}
		var tmpStr = "#"+ id ;
		 if( g_DisEnableBtnStyle == "hidden"){
			 if(enable == 1) //禁用
				{ 
				  tmpObj.fun_value  = parseInt(subFunc) + 10 ;  //禁用
				  $(tmpStr).removeClass("cb_btn_enable").addClass("cb_btn_disenable").css("display","none");
				  return ;
				}else{ 
				  tmpObj.fun_value  = parseInt(subFunc) ;  //可用
				  $(tmpStr).removeClass("cb_btn_disenable").addClass("cb_btn_enable").css("display","block");
				}
		 }else{
				if(enable == 1)
					{ 
					  tmpObj.fun_value  = parseInt(subFunc) + 10 ;  //禁用
					  $(tmpStr) .removeClass("cb_btn_enable").addClass("cb_btn_disenable") ;
					}else{ 
					  tmpObj.fun_value  = parseInt(subFunc) ;  //可用
					  $(tmpStr).removeClass("cb_btn_disenable").addClass("cb_btn_enable") ;
					}				 
		 }
	   switch(id)
	   {
		   case "btn_onoff_line": {
			   if(subFunc == 0)  //上线				   
			       tmpObj.innerHTML = "<span title='开启自动应答'>上线</span>"  ;// "咨  询" ;
			   else
				   tmpObj.innerHTML = "<span title='关闭自动应答'>下线</span>"  ;// "咨  询" ;
			   break ;
		   } 
		   //58
		   case "btn_ready_busy": {
				if(  
						callStateHelper.getCurCallState() == callStateHelper.busy
					||  callStateHelper.getCurCallState() == callStateHelper.busylogin
					||  callStateHelper.getCurCallState() == callStateHelper.busyonlinelogin
					||  callStateHelper.getCurCallState() == callStateHelper.busyonline			
					||  callStateHelper.getCurCallState() == callStateHelper.busyonline201	
					||  callStateHelper.getCurCallState() == callStateHelper.busy211						 
				)
					{
					   tmpObj.innerHTML = "忙碌" ;
					   tmpObj = document.getElementById("btn_readybusy_1");
					    if (tmpObj != null) {
					    	tmpObj.fun_value = 0;
					    	tmpObj.innerHTML = "空闲";
					    }
					    tmpObj = document.getElementById("btn_readybusy_2");
					    if (tmpObj != null) {
					    	tmpObj.fun_value = 2;
					        tmpObj.innerHTML = "小休";
					    }					 
					}
				else
                //小休
				if( 
						callStateHelper.getCurCallState() == callStateHelper.busyrest
					||  callStateHelper.getCurCallState() == callStateHelper.busyonlinerest
				)
					{
					   tmpObj.innerHTML = "小休" ;
					   tmpObj = document.getElementById("btn_readybusy_1");
					    if (tmpObj != null) {
					    	tmpObj.fun_value = 0;
					    	tmpObj.innerHTML = "空闲";
					    }
					    tmpObj = document.getElementById("btn_readybusy_2");
					    if (tmpObj != null) {
					    	tmpObj.fun_value = 1;
					        tmpObj.innerHTML = "忙碌";
					    }					 
					}
				else
				 //空闲
					{
					   tmpObj.innerHTML = "空闲" ;
					   tmpObj = document.getElementById("btn_readybusy_1");
					    if (tmpObj != null) {
					    	tmpObj.fun_value = 1;
					    	tmpObj.innerHTML = "忙碌";
					    }
					    tmpObj = document.getElementById("btn_readybusy_2");
					    if (tmpObj != null) {
					    	tmpObj.fun_value = 2;
					        tmpObj.innerHTML = "小休";
					    }					 
					}
				 
			   break ;
		   } 
		   case "btn_callout": {  
				   if(subFunc == 0)  //上线
					   tmpObj.innerHTML ="呼出" ;
				   else
					   tmpObj.innerHTML ="挂机" ; 
				   break ;			   
	       } 
	 	   case "btn_hold_unhold": {
			   if(subFunc == 0)  //上线
				   tmpObj.innerHTML = "保持" ;
			   else
				   tmpObj.innerHTML = "恢复" ;
			   break ;
	       } 
		   case "btn_toivr": {
			   tmpObj.innerHTML = "转调查" ;
		       break ;
	       } 
	
		   case "btn_music": {
			   tmpObj.innerHTML = "放音" ;
		       break ;
	       } 
		   case "btn_stop_music": {
			   tmpObj.innerHTML = "停止放音" ;
		       break ;
	       } 
		   case "btn_ivr_auth": {
			   tmpObj.innerHTML = "IVR鉴权" ;
		       break ;
	       }
		   case "btn_login": {
			   if(subFunc == 0)  //上线 
				   tmpObj.innerHTML = "签入" ;
			   else
				   tmpObj.innerHTML = "签出" ;
			   break ;
	       }	
		   case "btn_connect": {
			   tmpObj.innerHTML = "连接" ;
		       break ;
	       }
		   
		   //3合一功能：0：咨询， 1：退出咨询 内线、 2退出咨询外线
		   case "btn_consult": {  
			   if(subFunc == 0)  //上线 
				   tmpObj.innerHTML = "<span title='咨询坐席或外线'>咨询</span>"  ;// "咨  询" ;
			   else
				   tmpObj.innerHTML = "<span title='退出咨询'>结束</span>"  ;
			   break ;
	       }
		 //2合一功能：0：转坐席， 1：转外线， 都叫转接
		   case "btn_transfer": {
			   if(subFunc == 0)  //上线 
				   tmpObj.innerHTML = "<span title='转移到咨询坐席'>转接</span>"  ;// "咨  询" ;
			   else
				   tmpObj.innerHTML = "<span title='转移到外线'>转接</span>"  ;
			   break ;
	       }
		   //btn_confence 0=内三方，1=开始外三，2=结束内三方，3=结束外三	  	
		   case "btn_confence": {
			   if(subFunc == 0 || subFunc == 1)   
				   tmpObj.innerHTML = "会议" ;
			   else
				   tmpObj.innerHTML = "结束" ;
		       break ;
	       }	   
		     
		   //组长席功能
		   case "btn_monitor": {
			   tmpObj.innerHTML = "监听" ;
		       break ;
	       }
		   case "btn_stop_monitor": {
			   tmpObj.innerHTML = "结束监听" ;
		       break ;
	       }		   
		   
		   case "btn_force_join": {
			   if(subFunc == 0)   
				   tmpObj.innerHTML = "插话" ;
			   else
				   tmpObj.innerHTML = "结束插话" ; 
		       break ;
	       }
		   
		   case "btn_whisper": {
			   if(subFunc == 0)   
				   tmpObj.innerHTML = "耳语" ;
			   else
				   tmpObj.innerHTML = "结束耳语" ; 
		       break ;
	       }
		   
		   case "btn_tokeover": {
			   if(subFunc == 0){
				   tmpObj.innerHTML = "拦截" ;
			   }else{
				   tmpObj.innerHTML = "挂机" ;
			   }
		       break ;
	       }
		   case "btn_force_hungup": {
			   tmpObj.innerHTML = "强拆" ;
		       break ;
	       }		   
		   case "btn_force_login": {
			   tmpObj.innerHTML = "代签入" ;
			   break ;
	       }
		   case "btn_force_logout": {
			   tmpObj.innerHTML = "代签出" ;
			   break ;
	       }
	
		  
	   }
	} 
	 
	  
		
		/********************************************************************
		 * 注册坐席  采用后台鉴权方案
		 * @param entId    企业ID 
		 * @param tokenId    企业密码
		 * @param workNo    坐席工号
		 * @param extType   绑定电话类型：0：pstn电话坐席，1：sip，IP坐席
		 * @param extNum   坐席分机, 0 :以系统绑定的分机为准，非0 则以此为准，webrtc统一使用内部绑定方式
		 * @param isSipPhone 1:使用webrtc phone，0:使用其他IP话机
		 * @returns
		 ****************************************************************/
	function registCallBanner (entId,tokenId,workNo,extType,extNum,isSipPhone,cmsUrl)
		{
		    g_IsSipPhone = isSipPhone ==1 ? true:false ;
		    if(extNum =='' ||extNum==0){ extNum=0 ; extType=0 ;}
		    g_AcdInfo = {
		    		  entId:entId,     //企业编码
		    		  entPwd:"",  //企业账户密码
		    		  optId:workNo,   //坐席工号, 当前坐席的操作员号 
		    		  optPwd:"",
		    		  qId :0 ,
		    		  extType:extType, // 绑定电话类型：0：pstn电话坐席，1：sip，IP坐席
		    		  extNum:extNum,
		    		  loginType:0,      //签入方式： 0=坐席签入，这里固定用0， 1=外线签入（由班长席执行代签入时，有系统配置确定）
		    		  tokenId:tokenId
		    		};		    
		    g_AcdInfo.entPwd = _entPwd;
		    showSubStatus("开始向cmcc网关获取坐席电话中心登录许可！");
			 setTimeout( function(){
			cmsHelper.setCmsUrl(cmsUrl);
			cmsHelper.setAuthInfo(entId,workNo,tokenId);
			cmsHelper.getAcdInfo(onGetAcdInfo) ;				 	  	    
		 	    },1000) ;		  
		}  
	
	
		 
		 
  	 